import ErrorHandlerCode from './../../util/ErrorHandlerCode'
function ResHerderInterceptor(){
    return function ResHerderInterceptor(req, res, next){
        res.header("Access-Control-Allow-Origin",'*');
        res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
        res.header("Access-Control-Allow-Methods", "POST");
        res.header("Access-Control-Allow-Credentials", true);
        if((req.method).toUpperCase() === 'OPTIONS'){
            res.end();
            return;
        }
        if((req.method).toUpperCase() !== 'POST'){
            res.json(ErrorHandlerCode.REQUESTMETHODERROR);
            res.end();
        }else{
            next();
        }
    }
}

module.exports = ResHerderInterceptor;
